﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class Remind_Month_RemindofManger : System.Web.UI.Page
{
    Month_RemindofManager dllMonth_RemindofManager = new Month_RemindofManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    DepartmentInfoManager dllDepartment = new DepartmentInfoManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    Authentication dllAuthentication = new Authentication();

    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {
            #region 弹出提醒
            PopupManager dllPopupManager = new PopupManager();
            string _info = dllPopupManager.getPopupInfo();
            if (_info.Length > 0)
            {
                ShowMessage(_info);
            }
            #endregion
            BindGridView();
            bindDropDownList();
            bindPlanSponsor();
        }
    }

    /// <summary>
    /// 弹出小窗体事件
    /// </summary>
    /// <param name="msg"></param>
    public void ShowMessage(string msg)
    {
        EeekSoft.Web.PopupWin pop = new EeekSoft.Web.PopupWin();
        this.Controls.Add(pop);
        pop.Text = msg;
        pop.Message = msg;
        pop.Title = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
        pop.WindowScroll = true;
        pop.HideAfter = 99999999;
        pop.DockMode = EeekSoft.Web.PopupDocking.BottomLeft;
        pop.OffsetX = int.Parse(Session["_width"].ToString()) - 338;
        pop.ActionType = EeekSoft.Web.PopupAction.MessageWindow;
        pop.OffsetY = 1;
        pop.Width = 220;
        pop.Height = 170;
    }

    /// <summary>
    /// 绑定GridView
    /// </summary>
    /// <author>gzz</author>
    /// <date>2009-1-4</date>
    void BindGridView()
    {
        ////获得Session中登陆用户的用户名
        //object[] _user = new object[1];
        //_user[0] = objUserInfo.UserName;
        ////根据用户名获得用户真实姓名
        //DataTable _userInfo = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);
        //object[] _value = new object[2];
        //_value[0] = _userInfo.Rows[0]["DepartmentId"].ToString();
        //_value[1] = Convert.ToInt32(this.drpMonthDate.SelectedItem.Value);
        ////根据用户所在部门和当前时间查询月工作提醒
        //DataTable _monthRemind = dllMonth_RemindofManager.get(Month_RemindofManager.field.DepartmentName.ToString(), Month_RemindofManager.field.MonthDate.ToString(), _value);
        //if (_monthRemind.Rows.Count > 0)
        //{
        //    this.gdvMonthRemind.DataSource = _monthRemind;
        //    this.gdvMonthRemind.DataBind();
        //}     
        //else
        //{
        //    this.lblTopic.Text = "暂无月工作提醒！";
        //}
    }


    /// <summary>
    /// 绑定DropDownList
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-5</date>
    void bindDropDownList()
    {
        //绑定当前登陆人所在的部门
        object[] _value = new object[1];
        Model.UserInfo objUserInfo = new Model.UserInfo();
        _value[0] = objUserInfo.UserName;
        this.drpDepartmentName.DataSource = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _value);
        this.drpDepartmentName.DataTextField = "DepartmentId";
        this.drpDepartmentName.DataBind();
        
    }
    /// <summary>
    /// 绑定计划发起人等于登陆用户名
    /// </summary>
    /// <author>gzz</author>
    /// <date>2009-3-4 </date>
    void bindPlanSponsor()
    {
        object[] _sponsor = new object[1];
        Model.UserInfo objUserInfo = new Model.UserInfo();
        //获得Session中登陆用户的用户名
        _sponsor[0] = objUserInfo.UserName;
        //根据用户名获得用户真实姓名
        DataTable _userInfo = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _sponsor);
        if (_userInfo.Rows.Count > 0)
        {
            this.txtSponsor.Text = _userInfo.Rows[0]["RealName"].ToString();
        }
        else
        {
            dllAuthentication.isLogin();
        }
    }

    /// <summary>
    /// 月提醒删除事件 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>gzz</author>
    /// <date>2008-12-30</date>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        object[] _value = new object[1];
        _value[0] = Convert.ToInt32(this.gdvMonthRemind.Rows[i].Cells[0].Text);
       
        int result = dllMonth_RemindofManager.del(Month_RemindofManager.field.RemindId.ToString(),_value);
        if (result < 0)
        {
            Utility.Error.RedirectErrorPage("删除月提醒信息未成功，请重试！");
        }
        else
        {
            Response.Redirect("Month_RemindofManger.aspx");
        }
    }



    /// <summary>
    /// 添加月工作提醒事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date>2009-2-4</date>
    protected void btntijiao_Click(object sender, EventArgs e)
    {
        object[] _value = new object[4];//定义一个数组

        _value[0] = txtSponsor.Text;//等于当前登陆的用户的真实姓名 
        _value[1] =drpDepartmentName.SelectedItem.Text;//等于当前登陆用户所在的部门
        _value[2] = Convert.ToDateTime(txtCompleteTime.Text);
        _value[3] = txtTheMonthRemind.Text;
        int result = dllMonth_RemindofManager.add(_value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("添加月工作提醒未成功，请重试！");
        }
        else
        {
            Response.Redirect("Month_RemindofManger.aspx");
        }

    }
}
